﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyFrameWork.Dam;
using System.Data;
using MvcApplication5.Models;

namespace MvcApplication5.DAM
{
    public class RolePositionDAM : DataDAM
    {
        /// <summary>
        /// 创建连接数据库
        /// </summary>
        public RolePositionDAM()
        {
            this.CreateDataBase("MAINDB");
        }
        /// <summary>
        /// 获取角色信息表中的相应id的数据
        /// </summary>
        /// <param name="employee_id"></param>
        /// <returns></returns>
        public DataSet GetRoleInfoByRoleId(string role_id)
        {
            try
            {
                ConditionList conditionList = new ConditionList(ConditionList.ConditionType.AND);

                conditionList.Add("role_id", ConditionList.EquipType.EQUIP, role_id);

                conditionList.Add("record_status", ConditionList.EquipType.EQUIP, "0");

                return this.SelectData("TB_role", "*", conditionList, null);
            }
            catch (Exception ex)
            {
                return null;
            }

        }
        /// <summary>
        /// 新规角色
        /// </summary>
        /// <param name="model">角色model</param>
        /// <returns>受影响行数</returns>
        public int SavePositionInfo(RoleModel model)
        {
            try
            {
                return this.InsertData("TB_role", "role_id", model, null);
            }
            catch
            {
                return -1;
            }
        }
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="model">角色model</param>
        /// <returns>受影响行数</returns>
        public int UpdatePositionInfo(RoleModel model)
        {
            try
            {
                ConditionList conditionList = new ConditionList(ConditionList.ConditionType.AND);

                conditionList.Add("role_id", ConditionList.EquipType.EQUIP, model.role_id.ToString());

                Dictionary<string, string> targetList = new Dictionary<string, string>();

                targetList.Add("role_name", model.role_name.ToString());

                return this.UpdateData("TB_role", targetList, conditionList, null);
            }
            catch (Exception)
            {

                return -1;
            }
        }
    }
}